-
-
Notifications
You must be signed in to change notification settings - Fork 40
WIP: Fix CPython tests #54
base: master
Are you sure you want to change the base?
Conversation
@konstin thanks to the fix for PyO3/pyo3#177 I was able to add our own One issue that keeps popping up is, that the def test_unexpected_data(self):
test_cases = [
('[,', 'Expecting value', 1),
('{"spam":[}', 'Expecting value', 9),
('[42:', "Expecting ',' delimiter", 3),
('[42 "spam"', "Expecting ',' delimiter", 4),
('[42,]', 'Expecting value', 4),
('{"spam":[42}', "Expecting ',' delimiter", 11),
('["]', 'Unterminated string starting at', 1),
('["spam":', "Expecting ',' delimiter", 7),
('["spam",]', 'Expecting value', 8),
('{:', 'Expecting property name enclosed in double quotes', 1),
('{,', 'Expecting property name enclosed in double quotes', 1),
('{42', 'Expecting property name enclosed in double quotes', 1),
('[{]', 'Expecting property name enclosed in double quotes', 2),
('{"spam",', "Expecting ':' delimiter", 7),
('{"spam"}', "Expecting ':' delimiter", 7),
('[{"spam"]', "Expecting ':' delimiter", 8),
('{"spam":}', 'Expecting value', 8),
('[{"spam":]', 'Expecting value', 9),
('{"spam":42 "ham"', "Expecting ',' delimiter", 11),
('[{"spam":42]', "Expecting ',' delimiter", 11),
('{"spam":42,}', 'Expecting property name enclosed in double quotes', 11),
]
for data, msg, idx in test_cases:
with self.assertRaises(self.JSONDecodeError) as cm:
self.loads(data)
err = cm.exception
> self.assertEqual(err.msg, msg)
E AttributeError: 'JSONDecodeError' object has no attribute 'msg' I think, fixing that would make quite a few more tests pass. One thing that would be really fancy is supporting custom derives on structs to make them Python exceptions. Something like #[derive(PyException)]
struct JSONDecodeError {
msg: String,
} Have you considered this? I'm a bit reluctant to open an issue on pyo3, because... well... it's not really an issue. 😉 |
The easiest fix is to just add a msg field to the python object by name. Otherwise with PyO3/pyo3#291 everything is ready to implement a custom (Which should make a Good First Issue) |
See #8